import { SPublicMiniPlayer } from "../../../../../Message/Public/SPublicMiniPlayer";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { ColorConfig } from "../../../resource/ColorConfig";
import { AvatarInfo } from "../../../resource/info/AvatarInfo";
import { AvatarType } from "../../../resource/info/AvatarType";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class LoveTaskInviteItem
    
    export  class LoveTaskInviteItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        public get info(): SPublicMiniPlayer
        {
            return this._info;
        }

        /* internal  */onOkBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.LoveTaskInviteOk, this._info));
            return;
        }

        /* internal  */onNoBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.LoveTaskInviteNo, this._info));
            return;
        }

        /* internal  */onAvatorLoadedHandler(arg1: ImageInfo): void
        {
            if (arg1 && arg1.bitmapData) 
            {
                this._headImg.bitmapData = arg1.bitmapData;
            }
            return;
        }

        /* internal  */onRoleInfoClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.playerMenuLookPlayerInfo, this._info.entityId));
            }
            return;
        }

        protected initUI(): void
        {
            this._headMask = new Object /* flash.display.Sprite */();
            this._headMask.graphics.lineStyle(1, 0, 1);
            this._headMask.graphics.beginFill(0, 1);
            this._headMask.graphics.drawRect(0, 0, 22, 22);
            this._headMask.graphics.endFill();
            this._headMask.addEventListener(flash.events.MouseEvent.CLICK, this.onRoleInfoClickHandler);
            this._headMask.buttonMode = true;
            addChild(this._headMask);
            this._headImg = new Object /* flash.display.Bitmap */();
            this._headImg.x = 20;
            this._headImg.y = 0;
            this._headImg.scaleX = 0.5;
            this._headImg.scaleY = 0.5;
            addChild(this._headImg);
            this._headMask.x = this._headImg.x + 0;
            this._headMask.y = this._headImg.y + 0;
            this._nameBg = ObjCreate.createBg(this._headMask.x + this._headMask.width + 10, this._headImg.y, 115, 20, this, ImagesConst.DisabledBg);
            this._campBg = ObjCreate.createBg(this._nameBg.x + this._nameBg.width + 10, this._headImg.y, 40, 20, this, ImagesConst.DisabledBg);
            this._levelBg = ObjCreate.createBg(this._campBg.x + this._campBg.width + 10, this._headImg.y, 40, 20, this, ImagesConst.DisabledBg);
            var loc1=new GTextFormat("", 12, 16777215);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._nameText = ObjCreate.createGTextField("", this._nameBg.x, this._nameBg.y, this._nameBg.width, this._nameBg.height, this, loc1);
            this._nameText.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._nameText.addEventListener(flash.events.MouseEvent.CLICK, this.onRoleInfoClickHandler);
            this._campText = ObjCreate.createGTextField("", this._campBg.x, this._campBg.y, this._campBg.width, this._campBg.height, this, loc1);
            this._campText.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._levelText = ObjCreate.createGTextField("", this._levelBg.x, this._levelBg.y, this._levelBg.width, this._levelBg.height, this, loc1);
            this._levelText.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._okBtn = ObjCreate.createGButton(Language.getString(43529), this._headMask.x + 260, 0, 60, 20, this, "ButtonGreenStyle");
            this._noBtn = ObjCreate.createGButton(Language.getString(380003), this._okBtn.x + this._okBtn.width + 10, this._okBtn.y, 60, 20, this, "ButtonGreenStyle");
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOkBtnClickHandler);
            this._noBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onNoBtnClickHandler);
            return;
        }

        public updateData(arg1: SPublicMiniPlayer): void
        {
            this._info = arg1;
            this._nameText.text = Cache.instance.loveTask.getUserHtmlName(arg1, false);
            this._campText.htmlText = HTMLUtil.addColor(GameDefConfig.instance.getECamp(arg1.camp), ColorConfig.instance.getCampColor(arg1.camp).color);
            this._levelText.text = arg1.level + "级";
            AvatarInfo.getAvatar(this._info.camp, this._info.sex, AvatarType.TEAM, this.onAvatorLoadedHandler, this._info.avatarId);
            return;
        }

        public dispose(): void
        {
            this._info = null;
            this._nameText.text = "";
            this._headImg.bitmapData = null;
            return;
        }

        public /* override */ get height(): number
        {
            return 40;
        }

        /* internal */ /* var */_headImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_headMask: Object /* flash.display.Sprite */;

        /* internal */ /* var */_nameBg: ScaleBitmap;

        /* internal */ /* var */_campBg: ScaleBitmap;

        /* internal */ /* var */_levelBg: ScaleBitmap;

        /* internal */ /* var */_nameText: GTextFiled;

        /* internal */ /* var */_campText: GTextFiled;

        /* internal */ /* var */_levelText: GTextFiled;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_noBtn: GButton;

        /* internal */ /* var */_info: SPublicMiniPlayer;
    }
